﻿import request from '/@/utils/request';
enum Api {
  AddVistLogBlack = '/api/vistLogBlack/add',
  DeleteVistLogBlack = '/api/vistLogBlack/delete',
  UpdateVistLogBlack = '/api/vistLogBlack/update',
  SaveVistLogBlack = '/api/vistLogBlack/save',
  PageVistLogBlack = '/api/vistLogBlack/page',
  ExportVistLogBlack = 'api/vistLogBlack/export',
  ImportUrl= 'api/vistLogBlack/import',
  downLoadTemplate = 'api/vistLogBlack/TemplateDown',
  UploadIdCardImg = '/api/vistLogBlack/UploadIdCardImg',
  GetFlowSystemSGCompanyDropdown = `/api/vistLogBlack/FlowSystemSGCompanyDropdown`,
}

//导出訪客黑名單
export const exportVistLogBlackExcel=(params?:any)=>
	request({
		url:Api.ExportVistLogBlack,
		method:'post',
		data:params,
		responseType: 'blob'
	});

// 增加訪客黑名單
export const addVistLogBlack = (params?: any) =>
	request({
		url: Api.AddVistLogBlack,
		method: 'post',
		data: params,
	});

// 删除訪客黑名單
export const deleteVistLogBlack = (params?: any) => 
	request({
			url: Api.DeleteVistLogBlack,
			method: 'post',
			data: params,
		});

// 编辑訪客黑名單
export const updateVistLogBlack = (params?: any) => 
	request({
			url: Api.UpdateVistLogBlack,
			method: 'post',
			data: params,
		});

// 保存訪客黑名單
export const saveVistLogBlack = (params?: any) => 
	request({
			url: Api.SaveVistLogBlack,
			method: 'post',
			data: params,
		});

// 分页查询訪客黑名單
export const pageVistLogBlack = (params?: any) => 
	request({
			url: Api.PageVistLogBlack,
			method: 'post',
			data: params,
		});

export const importUrl = () => {return Api.ImportUrl;};
export const downLoadTemplate = ()=>{return Api.downLoadTemplate ;};


	/**
	* 上传证件照片 
	*/
export const uploadIdCardImg = (params: any) =>
		uploadFileHandle(params, Api.UploadIdCardImg)
export const getFlowSystemSGCompanyDropdown = (model) =>
		request({
		url: `${Api.GetFlowSystemSGCompanyDropdown}`,
		method: 'post',
		data: model
		});

	export const uploadFileHandle = (params: any, url: string) => { 
	const formData = new window.FormData();
	formData.append('file', params.file);
	//自定义参数
	if (params.data) {
		Object.keys(params.data).forEach((key) => {
			const value = params.data![key];
			if (Array.isArray(value)) {
				value.forEach((item) => {
					formData.append(`${key}[]`, item);
				});
				return;
			}
			formData.append(key, params.data![key]);
		});
	}
	return request({
		url: url,
		method: 'POST',
		data: formData,
		headers: {
			'Content-type': 'multipart/form-data;charset=UTF-8',
			// ts-ignore
			ignoreCancelToken: true,
		},
	});
};
